import metchonServices from '@/services/metchonService.js';
import tableData from './tableData.js';

export default {
	data() {
		return {
			searchType: '',
			tableData: [],
			// 每页数据量
			pageSize: 10,
			// 当前页
			pageCurrent: 1,
			// 数据总量
			total: 0,
			loading: false
		}
	},
	async onLoad(option) {
		await this.$store.dispatch('checkLoginAction');
		this.searchType = option.searchType;
		if(this.searchType === 'weixiu'){
			uni.setNavigationBarTitle({
				title: '故障列表'
			});
		}else if (this.searchType === 'xunjian') {
			uni.setNavigationBarTitle({
				title: '巡检列表'
			});
		}else{
			uni.setNavigationBarTitle({
				title: '设备列表'
			});
		}
		
		this.getData(1);
	},
	methods: {
		// 分页触发
		change(e) {
			this.$refs.table.clearSelection()
			this.getData(e.current)
		},
		// 获取数据
		async getData(pageCurrent, value = '') {
			this.loading = true;
			this.pageCurrent = pageCurrent;
			var result = [];
			if(this.searchType === 'weixiu'){
				result = await metchonServices.faultList(pageCurrent,this.pageSize);
			}else if (this.searchType === 'xunjian') {
				result = await metchonServices.inspectionList(pageCurrent,this.pageSize);
			}else{
				result = await metchonServices.list(pageCurrent,this.pageSize);
			}
			 
			this.tableData = result.records;
			console.log('this.tableData',this.tableData)
			this.total = result.total;
			this.loading = false;
		},
		async onDelete(row){
			uni.showModal({
				title: '提示',
				content: '确认删除？',
				success: async function (res) {
					if (res.confirm) {
						console.log('用户点击确定');
						await metchonServices.delete(row.id)
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		async onEdit(row){
			
		},
		onDetail(row) {
			if(this.searchType === 'weixiu'){
				this.$tool.goToPage(`/pages/WeiXiuDetail/index?id=${row.id}`)
			}else if (this.searchType === 'xunjian') {
				this.$tool.goToPage(`/pages/XunJianDetail/index?id=${row.id}`)
			}else{
				this.$tool.goToPage(`/pages/TianJiaDetail/index?sbewm=${row.sbewm}`)
			}
			
		}
	}
}